/*
 * Copyright (C) Francisco Morero Peyrona. All rights reserved.
 *
 * This software is published under the terms of Open Source 
 * License version 1.1, a copy of which has been included with this
 * distribution in the License.txt file.  
 */

package jdbcmanager.swing;

import java.awt.*;
import javax.swing.border.*;
import javax.swing.*;

/**
 * Creates a Splash screen with an app logo. <br>
 * The window can be shown/hidden using setVisible(); <br>
 * Window adjust its size base on the logo image size. <br>
 * 
 * @author Francisco Morero Peyrona
 */

public final class JSplash extends JWindow
{
	private JLabel lblVersion = new JLabel();

	/**
	 * Creates a Splash screen
	 */
	public JSplash()
	{
		init();
		setLocationRelativeTo( null );
	}

	/**
	 * 
	 * @param sVersion
	 */
	public void setVersion( String sVersion )
	{
		this.lblVersion.setText( "Version " + sVersion );
	}

	//-------------------------------------------------------------------------//

	private void init()
	{
		JPanel    pnlImage     = new JPanel();
		ImageIcon image        = new ImageIcon( getClass().getResource( "images/logo.gif" ) );
		JLabel    lblBack      = new JLabel( image );
		Border    raisedbevel  = BorderFactory.createRaisedBevelBorder();
		Border    loweredbevel = BorderFactory.createLoweredBevelBorder();

		lblBack.setBounds( 0, 0, image.getIconWidth(), image.getIconHeight() );
		getLayeredPane().add( lblBack, new Integer( Integer.MIN_VALUE ) );

		pnlImage.setLayout( null );
		pnlImage.setOpaque( false );
		pnlImage.setBorder( BorderFactory.createCompoundBorder( raisedbevel, loweredbevel ) );

		pnlImage.add( this.lblVersion );

		this.lblVersion.setForeground( Color.white );
		this.lblVersion.setFont( new Font( "Dialog", Font.PLAIN, 12 ) );
		this.lblVersion.setBounds( 15, 69, 120, 20 );

		setContentPane( pnlImage );
		setSize( image.getIconWidth() + 2, image.getIconHeight() + 4 ); // +4 because the border
	}
}